Speeding up co-occurrence

Instead of looping through all possible indices looping through only
existing indices. In theory useful for thresholds 23 or more for
pictures 512*512, in practice even sooner.