Outline Exclusion

Hey guys. I am playing around with with PP material lately trying to make outline around specific objects. So I would have some meshes with the outline and some without it. I’ve managed to get pretty close to it by using custom depth and stencil buffers. However there is slight issue that appears as seen on image. When I put mesh without outline in front of the one with outline, you can see some outline on it (left part of cube). Theoretically I know why this happens, but I have no idea how to get around it. Any ideas?