You should wave at someone who is waving at you.
Tom is walking down the street when he sees a guy he knows waving at him from across the street.
Tom wants to react to the guy waving at him.
Tom waves back at the guy waving at him in a friendly way before going on his way.
Tom just looks at the guy for a few seconds then looks away and keeps walking down the street.
The guy is happy to have seen Tom and thinks Tom is friendly.
The guy who was waving at Tom is hurt and confused by Tom's reaction and figures Tom might have forgotten who the guy is.