Fix input image indexing bug in filter()