You are almost there, remove the Scene Depth node and replace it with the number of the stencil channel you want to mask (0-255).
You are almost there, remove the Scene Depth node and replace it with the number of the stencil channel you want to mask (0-255).