A good way to render objects on a photo background that works also with focus-blurred margins
As 3dpointedit pointed out, there is a limitation of the current ID mask system:

Is Z-Render Pass accuracy dependent on sample count? Are others like object id? (Cycles)

As such, these layers are unusable for any post-processing workflow. You need to obtain these layers differently, or build the pipeline in another way.

The correct way of compositing onto a background is detailed here:

Cycles: Shadeless &quot;Shadow-catcher&quot; Material for Rendering onto Footage

In short, you need to put your objects in layer 1, your shadow catchers in layer 2, and the lights in both layers. The render layers will be "object only" (include: 1), "shadows" (include: 2), and "clean background" (include: 2, exclude: 1). Render with transparent background.

This will give you these layers:


"shadows"

 
"clean background"




Dividing the former with the latter you get the shadow:



You multiply this shadow with your backdrop, and you alpha-over the object into your backdrop. You have to render the scene 3 times though.

You can also use the new Shadow catcher feature of Blender 2.79, but it will only produce black shadows.