Basically, you can act as if you have a mask.
Let be your first image A and the second one B. You want fill with B everywhere A is completely black. It translates directly into Matlab as:
C = zeros(size(B,1), size(B,2),3);
C(startRow:startRow+size(A,1)-1, startCol:startCol+size(A,2)-1,:) = A;
M = repmat(sum(C,3)==0,1,1,3);
C(M) = B(M);
I expand the mask M over the 3 dimensions to be usable directly as a mask.