Before vocal or written language even existed, humans needed a way to communicate their ideas and feelings, and gesturing is the easiest way to go about this problem. Now, since the advent of language, the innate desire to use one's hands still exists, even though it is not necessary to do so all of the time.
Isn't it also something to do with being able to see and be seen in a crowd? to let another know that you are there and waving you hand will be easily seen by the eye so the person will know you are there? just a guess.
Also it could have something to do with demonstrating that you do not have a weapon in your hand - so you will not try to hurt the person you are waving to.