Both the use of very large arrays of antennas and flexible time division duplexing (TDD) designs have become prominent features of next generation 5G cellular systems. However, both enabling technologies suffer from severe interference effects, respectively known as pilot contamination and base-station-to-base-station (B2B) interference. In this paper, a practical novel TDD design principle is proposed for massive multiple-input multiple-output (MIMO) heterogeneous networks (HetNets) that leverages the inherent features of a flexible TDD design to mitigate both the beamformed interference caused by the pilot contamination effect and B2B interference. The design is based on the key observation that the transmission path chosen for training by the non-massive MIMO base stations plays an important role in the interference behavior of the network, and the data slots need to be configured accordingly. We propose TDFLEX, a low-complexity heuristic solution that follows these design guidelines. Performance evaluation results show significant gains when our design is compared to the standard TD-LTE.