My understanding is that the particulate matter in the various layers of earth’s atmosphere get in the path of the photons traveling toward us; the twinkling is the particles briefly diffracting the light as they pass that path; if the atmosphere is more dense with material (dust, ions, water vapor, smog, etc.) the apparent effect would be more twinkling. I have heard that in outer space, there is little-to no twinkling effect as there are far fewer particles in zero atmospheric conditions.