Question: I found the Homography matrix following the [Feature Matching + Homography tutorial](https://docs.opencv.org/3.4.1/d1/de0/tutorial_py_feature_homography.html) using

```
M, mask = cv2.findHomography(src_pts, dst_pts, cv2.RANSAC,5.0)

```

and now I need to warp the second image (rotated one) to match the keypoints of the first one, so I tried to do with `warpPerspective` directly on `img2` since we have the Homography matrix already. (They did not use warpPersective in the tutorial)

```
dst = cv2.warpPerspective(img2, M)

```

and it complains that I'm missing the third argument

```
TypeError: Required argument 'dsize' (pos 3) not found

```

Fair enough, I checked what `dsize` is in the [docs](https://docs.opencv.org/2.4/modules/imgproc/doc/geometric_transformations.html#warpperspective), and it seems it's the destination image size. Well, it could be inferred if not given, but opencv is expecting it, (grrr... fine opencv, I'll give you that). I tried again

```
dst = cv2.warpPerspective(img2, M, img2.shape)

```

and it throws

```
TypeError: function takes exactly 2 arguments (3 given)

```

Wait, didn't I try it with 2 arguments just a minute ago?

**What's wrong?**

Answer: 
Although it might be so counter-intuitive, for some reason, opencv has implemented `warpPerspective` function in this way:

```
corrected_image = cv2.warpPerspective(img1, M, (img1.shape[1], img1.shape[0]))

```

Also noticed that M obtained is for the mapping the first image to the second, which means I can use M on the first image to warp it and make it overlap with the second. (I was trying to use it on the img2 as shown in the question and it won't work)

And the reason for **funny exceptions** is NOT known yet. (Please feel free to update this answer if you know why)
The problem with what you are doing is that you are passing 3 parameters instead of 2 to the "shape" argument. A perspective transform is performed on a gray-scale image which has shape as (H,W). A RGB image has shape (H,W,3) where the last dimension shows the number of channels--red, green and blue. Try with gray-scale image and no errors will be there :)

Edit :
======

Just saw the date. Guess I am too late :P