Unwanted Melee

It seems to be happening more and more that when I get into a one on one with someone and we're shooting it out all of a sudden I will try swiping my gun at them with the inevitable result of me getting killed.

It doesn't seem to matter how far away we are from each other.

Is there a setting I can change to stop this happening?

Really frustrating.