Fixed self-assignment in cv::Ptr::operator =

A self-assignment leads to a call of release() with refcount being 2. In the release() method, refcount is decremented and then successfully checked for being 1. As a consequence, the underlying data is released. To prevent this, we test for a self-assignment.

**EDIT**: As pointed out in the comments, this is not the true cause of the error. The problem is the execution of [the last two lines in the method release()](https://github.com/PhilLab/opencv/blob/patch-2/modules/core/include/opencv2/core/operations.hpp#L2608-L2609). Independent of the error's cause, this PR enables the following program to run **/EDIT**

The current error can be reproduced by executing the following statements:
```cpp
cv::Ptr<cv::Mat> a(new cv::Mat(5,5, CV_8UC3));
a->setTo(100);
a = a;
cv::imshow("test", *a);
```