I've done this too many times. And then when I figure out that they're waving at me, I would look left and right and then point at myself with a confused face.
It happens the opposite for me. I wave back and it turns out they were waving to the person behind me.