Mesh masking of blur
I think you are looking for the ID Mask node.  For an example, I set up a simple scene with one object inside of the other.



If you go to the Render Layers tab and check the box next to the material index pass, it will now add a pass for all of the different material indexes.



Next, you have to set the indexes of your materials.  In the materials tab, go to the bottom of the material that you want to set the pass index of.  In the very bottom, under settings, there is a setting that says Pass Index.  You can set that to whatever number you want to use for that material.  The default for the background is 0, so I set my material pass indexes to 1 and 2.



After Rendering, open the compositor and get an ID Mask node.  Plug the IndexMA output from the Render Layers node into the input of the ID Mask node.  Then you can connect the Alpha output of the ID Mask node into the input of a viewer node to see the result.  You can then change the index value of the ID Mask node to whatever index you set your material indexes to.



You can then use the ID Mask node for what it says it is, a mask.