     int idx     = block_x + threadIdx.x;
     int idy     = blockIdx.y;
 
-    if( idx >= dst.cols ) return;
-    if( idy >= dst.rows ) return;
+    if( outOfBounds( idx, idy, dst ) ) return;
 
     int16_t dx = src_dx.ptr(idy)[idx];
     int16_t dy = src_dy.ptr(idy)[idx];

    int idx     = block_x + threadIdx.x;
    int idy     = blockIdx.y;

    if( idx >= dst.cols ) return;
    if( idy >= dst.rows ) return;

    int16_t dx = src_dx.ptr(idy)[idx];
    int16_t dy = src_dy.ptr(idy)[idx];
    dx = (dx < 0 ) ? -dx : dx;
    dy = (dy < 0 ) ? -dy : dy;
    dst.ptr(idy)[idx] = dx + dy;
}



#define V7_WIDTH    32

__device__
inline
bool outOfBounds( int x, int y, const cv::cuda::PtrStepSzb& edges )
{
    return ( x < 0 || x >= edges.cols || y < 0 || y >= edges.rows );
}

__device__
template <typename T>
inline T d_abs( T value )
{
    return ( ( value < 0 ) ? -value : value );
}

__device__
template <typename T>
inline int d_sign( T value )
{
    return ( ( value < 0 ) ? -1 : 1 );
}

template <class DestType>
__global__
void filter_gauss_horiz( cv::cuda::PtrStepSzf          src,
