As per OpenCV 3.x API, all drawing functions return the input image after editing. That means, after drawing the rectangle, both 'frame' and 'img2' are same. But the function does return the image (unlike in OpenCV 2.x). And this tutorial is meant for OpenCV 3.x. So I think it is better to revert it.