fix bug #3552

replace `std::swap` with own code

For: http://code.opencv.org/issues/3552