     const int ddepth = dst.depth();
     const int cn = src.channels();
 
-    CV_DbgAssert( sdepth <= CV_64F && ddepth <= CV_64F && cn <= 4 );
+    CV_DbgAssert( sdepth <= CV_64F && ddepth <= CV_64F && cn <= 4 && src.type() == dst.type());
 
-    const func_t func = funcs[sdepth][ddepth][cn - 1];
-
+    const func_t func = funcs[sdepth][cn - 1];
     if (!func)
         CV_Error(cv::Error::StsUnsupportedFormat, "Unsupported combination of source and destination types");
 

        };
    };

    template <typename SrcType, typename ScalarDepth, typename DstType>
    void absDiffScalarImpl(const GpuMat& src, cv::Scalar value, GpuMat& dst, Stream& stream)
    {
        typedef typename MakeVec<ScalarDepth, VecTraits<SrcType>::cn>::type ScalarType;

        cv::Scalar_<ScalarDepth> value_ = value;

        AbsDiffScalarOp<SrcType, ScalarType, DstType> op;
        op.val = VecTraits<ScalarType>::make(value_.val);
        gridTransformUnary_< TransformPolicy<ScalarDepth> >(globPtr<SrcType>(src), globPtr<SrcType>(dst), op, stream);
    }


namespace
{
    template <typename SrcType, typename ScalarType> struct AbsDiffScalarOp : unary_function<SrcType, SrcType>
    {
        ScalarType val;

        __device__ __forceinline__ SrcType operator ()(SrcType a) const
        {
            abs_func<ScalarType> f;
            return saturate_cast<SrcType>(f(saturate_cast<ScalarType>(a) - val));
        }
    };

