It's done as a courtesy by some when being followed by other riders.
It is sometimes useful when riding in large groups - impossible to actually see an intersection, etc. The signal usually makes its way through the pack quickly.
If you need both brakes to come to a quick stop then odds are something more drastic is happening. Instead of signalling the rider in front might say something like, "Oh Sh**!"
Either way, just keep your eyes on the road and riders in front of you. When in front ride as though if you were to do something unusual you will end up with a couple a hundred pounds of human and bike firmly planted in your ass....because if you do something unexpected that may in fact be the result.