Kuwahara effect masked on scene depth

I had a scene with different layer (foregorund, centre and backgorund) and i tried to use the compositiong nodes to apply the kuwahara distortion only to object out of focus (See Goat where everytime something was too close or too far from the camera it would get warpy and had the same type of voronoi-ish effect applied on it)

at first i tried directly hooking the depth pass from the render output into the scale of the kuwahara node but it literally made blender cry and restart, i also tried different nodes that would give the same effec like using the mist pass with a colorramp to accentuate the parts that i wanted masked out but the node would just ignore it and cancel any overall distortion on the image, i’m open to ideas

Did you have seen this ? From some some days ago:

yeah i kinda figured that exact same way a few sec ago, it’s hard to control cause if you aplly some range regulator like a colorramp the pass will be transalted into a plane color so my only only option is to tweak math nodes and see how can i refine the limits of the “mask”