Why not throw the "matrix" var out of the function and pass it as parameter instead?
That way the developer does not have to adjust the code for each terrain and he can use it in multiple levels with different terrains:
Code:

function sew_top_to_bottom(ent1,ent2,matrix) // sew top of ent1 to the bottom of ent2
{
my = ent1;
you = ent2;

var vpos;
var vpos2;
var i=0;

while(i < matrix)
{
i+=1;
vec_for_mesh(vpos,my,i); //my top row
vec_for_mesh(vpos2,you,matrix*(matrix-1) + i);//your bottom row
vpos.z += (vpos2.z + you.z/you.scale_z) - (vpos.z + my.z/my.scale_z);
vpos.x += (vpos2.x + you.x/you.scale_x) - (vpos.x + my.x/my.scale_x);
vpos.y += (vpos2.y + you.y/you.scale_y) - (vpos.y + my.y/my.scale_y);
vec_to_mesh(vpos,my,i); //move my top row vert
}
}

//
function sew_left_to_right(ent1,ent2,matrix) // sew left of ent1 to the right of ent2
{
my = ent1;
you = ent2;

var vpos;
var vpos2;
var i=0;

while(i < matrix)
{
i+=1;
vec_for_mesh(vpos,my,matrix*i-(matrix-1)); //my left edge
vec_for_mesh(vpos2,you,matrix*i); //your right edge
vpos.z += (vpos2.z + you.z/you.scale_z) - (vpos.z + my.z/my.scale_z);
vpos.x += (vpos2.x + you.x/you.scale_x) - (vpos.x + my.x/my.scale_x);
vpos.y += (vpos2.y + you.y/you.scale_y) - (vpos.y + my.y/my.scale_y);
vec_to_mesh(vpos,my,matrix*i-(matrix-1)); //move my left edge vert
}
}