First of all your collision check is wrong. The distance between 2 points is sqrt((x1-x2)^2+(y1-y2)^2)
Second, the way you are reversing directions is wrong. Balls don't move that way. Nothing moves that way. You might want to google conservation of momentum to understand theory socks behind ball collision
Third, I hope you are updating the ball positions in the same
thread as ball collision. If the ball collision check is called multiple times before the ball positions are updated, they will reverse direction multiple times. This will result in your balls being weird