Conditions for production of terrestrial gamma-ray flashes