 
             template<typename I> __device__ __forceinline__ bool operator() (const I& a, const I& b) const
             {
-                T d = a - b;
+                I d = a - b;
                 return lo <= d && d <= hi;
             }
         };
 
         template<typename T> struct InInterval<T, 3>
         {
-            __host__ __device__ __forceinline__ InInterval(const float4& _lo, const float4& _hi){};
+            __host__ __device__ __forceinline__ InInterval(const float4& _lo, const float4& _hi)
+            : lo (VecTraits<T>::make(-_lo.x, -_lo.y, -_lo.z)), hi (VecTraits<T>::make(_hi.x, _hi.y, _hi.z)){};
             T lo, hi;
 
             template<typename I> __device__ __forceinline__ bool operator() (const I& a, const I& b) const
             {
-                return true;
+                I d = a - b;
+                return lo.x <= d.x && d.x <= hi.x &&
+                       lo.y <= d.y && d.y <= hi.y &&
+                       lo.z <= d.z && d.z <= hi.z;
             }
         };
 
         template<typename T> struct InInterval<T, 4>
         {
-            __host__ __device__ __forceinline__ InInterval(const float4& _lo, const float4& _hi){};
+            __host__ __device__ __forceinline__ InInterval(const float4& _lo, const float4& _hi)
+            : lo (VecTraits<T>::make(-_lo.x, -_lo.y, -_lo.z, -_lo.w)), hi (VecTraits<T>::make(_hi.x, _hi.y, _hi.z, -_hi.w)){};
             T lo, hi;
 
             template<typename I> __device__ __forceinline__ bool operator() (const I& a, const I& b) const
             {
-                return true;
+                I d = a - b;
+                return lo.x <= d.x && d.x <= hi.x &&
+                       lo.y <= d.y && d.y <= hi.y &&
+                       lo.z <= d.z && d.z <= hi.z &&
+                       lo.w <= d.w && d.w <= hi.w;
             }
         };
 

// the use of this software, even if advised of the possibility of such damage.
//M*/

#include "opencv2/gpu/device/common.hpp"
#include <iostream>
#include <stdio.h>



        template<> struct IntervalsTraits<uchar4>
        {
            typedef int4 dist_type;
            enum {ch = 4};
        };

