When you hold a lens in front of a light source, the lens makes the light either increase or decrease in brightness, depending on whether that lens is enlarging or shrinking the image.
Air varies in density from place to place because of heat and wind. As a pocket of warmer or cooler air passes between you and a distant star, that pocket acts as a lens because light is bent at the effective "surface" of that pocket. Though there is no "solid surface," a "cell" of air acts as if it has a surface, because of the changes in density. This lensing effect causes each star to brighten or dim depending on the shapes of the intervening cells of air.
Planets in our own Solar system, however, don't twinkle nearly as much because they are not point sources like stars. The planets have a measurable disk when magnified by a telescope. Because of this, one side of the planet may be experiencing a brightening while the other side experiences a dimming, effectively canceling out the overall twinkling effect.