There's at least one thing going on here. This operation
will return a 179x183 logical image, which is smaller than the source image. This is going to cause an indexing problem -- not necessarily an error, but it won't be addressing the same part of the image. You're doing two indexing operations here. One based on the ROI location, and one based on the logical comparison. You need to keep track of both. This is a simple way:
A = imread('cameraman.tif');
Aroi = A(y(1):y(2),x(1):x(2));
Aroi(Aroi<threshold) = 0;
A(y(1):y(2),x(1):x(2)) = Aroi;
That said, the above issue shouldn't be causing an out-of-bounds error since the ROI is smaller than the parent image. If you're getting an error like that, you might want to make sure that your subscripts are in the right order (y,x instead of x,y).